//
//  NSString+Attributes.m
//  qmjianqian
//
//  Created by huanchi on 15/8/20.
//  Copyright (c) 2015年 Shawn. All rights reserved.
//

#import "NSMutableAttributedString+Attribute.h"

@implementation NSMutableAttributedString (Attributes)

-(NSMutableAttributedString *)attributeInRange:(NSRange)range textColor:(UIColor*)color{
    if (!color) {
//        color = COLOR_TEXT;
    }
    [self addAttribute:NSForegroundColorAttributeName value:color range:range];
    return self;
}


-(NSMutableAttributedString *)attributeInRange:(NSRange)range textFont:(UIFont *)font{
    if (!font) {
//        font = FONT_TEXT;
    }
    [self addAttribute:NSFontAttributeName value:font range:range];
    return self;
}

-(NSMutableAttributedString *)attributeInRange:(NSRange)range textLineSpace:(CGFloat)space textAlign:(NSTextAlignment)align{
    NSMutableParagraphStyle *parag = [[NSMutableParagraphStyle alloc]init];
    parag.lineSpacing = space;
    parag.alignment = align;
    [self addAttribute:NSParagraphStyleAttributeName value:parag range:range];
    return self;
}
@end

@implementation NSMutableAttributedString (textHeight)

-(CGFloat)heightInSize:(CGSize)size{
    CGRect rect=[self boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin context:nil];
    return rect.size.height;
}
@end
